﻿using System;
using System.ServiceModel;
using ReadlingList.Services;
using System.ServiceModel.Description;
using ReadingList.Contracts.ServiceContracts;

namespace ReadingList.SelfHost
{
    class Program
    {
        static void Main(string[] args) {
            RegisterHosts();
        }

        private static void RegisterHosts() {
            string bookServiceBaseAddress = "http://MMI-LP1-IT3:8020/ReadingList/Books";

            ServiceHost bookServiceHost = new ServiceHost(typeof(BookService), new Uri(bookServiceBaseAddress));

            WebHttpBinding binding = new WebHttpBinding();
            binding.ReaderQuotas.MaxArrayLength = 2147483647;
            binding.ReaderQuotas.MaxStringContentLength = 2147483647;
            binding.ReaderQuotas.MaxDepth = 2147483647;
            binding.ReaderQuotas.MaxNameTableCharCount = 2147483647;
            binding.ReaderQuotas.MaxBytesPerRead = 2147483647;
            binding.OpenTimeout = new TimeSpan(0, 10, 0);
            binding.CloseTimeout = new TimeSpan(0, 10, 0);
            binding.ReceiveTimeout = new TimeSpan(0, 10, 0);
            binding.SendTimeout = new TimeSpan(0, 10, 0);

            ServiceMetadataBehavior behavior = new ServiceMetadataBehavior();
            behavior.HttpGetEnabled = true;

            ServiceThrottlingBehavior throttlingBehavior =
                new ServiceThrottlingBehavior();
            throttlingBehavior.MaxConcurrentCalls = 16;
            throttlingBehavior.MaxConcurrentInstances = Int32.MaxValue;
            throttlingBehavior.MaxConcurrentSessions = 10;

            // Add Endpoints
            bookServiceHost.AddServiceEndpoint(typeof(IBookService), binding, "")
                .Behaviors.Add(new WebHttpBehavior());

            bookServiceHost.Open();

            Console.WriteLine("Services running... Press <Enter> to quit.");
            Console.Read();

            bookServiceHost.Close();
        }
    }
}
